﻿using System;
using System.Web.UI;
using System.Net.Mail;

namespace Nurturehood
{
    public partial class Career : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSubmit_OnClick(object sender, EventArgs e)
        {
            using (MailMessage message = new MailMessage())
            {
                message.From = new MailAddress(txtEmail.Text);
                message.To.Add(new MailAddress("contact@nurturehood.com"));
                message.Subject = txtName.Text + " wants to know career opportunities @ Nurturehood.";

                Attachment attachFile = new Attachment(fuResume.PostedFile.InputStream, fuResume.FileName);
                message.Attachments.Add(attachFile);

                message.Body = "Hi,\n\n" + txtName.Text + " wants to know career opportunities @ Nurturehood. The date of birth is " + 
                    datepicker.Value.ToString() +". Please find the resume attached to this mail. The Mobile number is " + txtMobile.Text +
                    " and current location is " + txtLocation.Text +".\n\n Thanks\n Nurturehood";
                SmtpClient client = new SmtpClient();
                //This is GoDaddy email hosting server
                client.Host = "relay-hosting.secureserver.net";
                client.Send(message);
                ResetForm();
                Page.ClientScript.RegisterClientScriptBlock(GetType(), "emailsent", "alert('Your details are sent to our HR team. They will get back to you shortly.')",true);
            }
        }

        private void ResetForm()
        {
            txtEmail.Text = string.Empty;
            txtLocation.Text = string.Empty;
            txtMobile.Text = "0";
            txtName.Text = string.Empty;
            datepicker.Value = string.Empty;
        }
    }
}